
<h1>More Go Related Topics</h1>

<p>
Go 101 articles mainly focus on syntax and semantics in Go.
There are some other Go related topics which are not covered in Go 101.
The remaining of the current article will make simple introductions
to those topics and provide some web links for readers to dig more into them.
</p>

<h3>Profiling, Tests and Benchmarks</h3>

<div>
We can use <code>go test</code> command in the official SDK to run tests and benchmarks.
Test source file names must end with <code>_test.go</code>.
The official Go SDK also supports profiling Go programs.
Please read the following articles for more details.
<ul>
<li>
	<a href="https://golang.org/pkg/testing/">The testing standard package</a>.
</li>
<li>
	<a href="https://blog.golang.org/subtests">Using subtests and sub-benchmarks</a>.
</li>
<li>
	<a href="https://golang.org/cmd/go/#hdr-Test_packages"><code>go test</code> command options</a>.
</li>
<li>
	<a href="https://github.com/golang/go/wiki/Performance">Profiling Go programs</a>.
</li>
</ul>
</div>


<h3>gccgo</h3>

<p>
<a href="https://github.com/golang/gofrontend">gccgo</a> is another Go compiler maintained by the Go core team.
It is mainly used to verify the correctness of the standard Go compiler (gc).
We can use the <code>-compiler=gccgo</code> build option in several official Go SDK
commands to use the gccgo compiler instead of the gc compiler.
For example, <code>go run -compiler=gccgo main.go</code>.
This option requires the gccgo program is installed.
Once the gccgo program is installed,
we can also <a href="https://golang.org/doc/install/gccgo#Using_gccgo">use the <code>gccgo</code> command directly to compile Go code</a>.
</p>

<h3>Go Assembly</h3>

<p>
Go functions can be implemented with Go assembly language.
Go assembly language is a cross-architectures (though not 100%) assembly language.
Go assembly language is often used to implement some functions
which are critical for Go program execution performances.
</p>

<div>
For more details, please follow the following links.
<ul>
<li>
	<a href="https://golang.org/doc/asm">A quick guide to Go's assembler</a>
</li>
<li>
	<a href ="https://talks.golang.org/2016/asm.slide">The Design of the Go assembler</a>
</li>
</ul>

</div>

<a class="anchor" id="cross-platform-compiling"></a>
<h3>Cross-Platform Compiling</h3>

<div>
The standard Go compiler supports cross-platform compiling.
By setting the <code>GOOS</code> and <code>GOARCH</code> environments
before running the <code>go build</code> command,
we can build a Windows executable on a Linux machine, and vice versa.
Please read the following articles for details.
<ul>
<li>
	<a href="https://github.com/golang/go/wiki/WindowsCrossCompiling">Building windows go programs on linux</a>.
</li>
<li>
	<a href="https://golang.org/doc/install/source#environment">The current supported target operating systems and compilation architectures</a>.
</li>
</ul>

In particular, since Go 1.11, the official Go SDK starts to support WebAssembly as a new kind of GOARCH.
Please read <a href="https://github.com/golang/go/wiki/WebAssembly">this wiki article</a> for details.
</div>

<h3>cgo</h3>

<div>
We can call C code from Go code, and vice versa, through the cgo mechanism.
Please follow the following links for details.
<ul>
<li>
	<a href="https://golang.org/cmd/cgo/">cgo official documentation</a>
</li>
<li>
	<a href="https://blog.golang.org/c-go-cgo">C? Go? Cgo!</a>
</li>
<li>
	<a href="https://github.com/golang/go/wiki/cgo">cgo on Go wiki</a>
</li>
</ul>

<p>
It is possible to use C++ libraries through cgo by wrapping C++ libraries as C functions.
</p>

<p>
Please note that using cgo in code may make it is hard to maintain
cross-platform compatibility of Go programs,
and the calls between Go and C code are some less efficient than Go-Go and C-C calls.
</p>
</div>

<h3>Build Constraints (Tags)</h3>

<p>
We can use <a href="https://golang.org/pkg/go/build/">build constraints</a>
to let compilers build source files selectively.
A build constraint is also called a build tag.
A build constraint can appear as a comment line like <code>// +build constraints</code>
or appear as the suffix in the base name of a source file.
</p>

<h3>Compiler Directives</h3>

<p>
The standard Go compiler supports several
<a href="https://golang.org/cmd/compile/#hdr-Compiler_Directives">compiler directives</a>.
A directive appears as a comment line like <code>//directive args</code>.
The most used compiler directive in practice may be the
<a href="https://blog.golang.org/generate">go:generate</a> directive.
</p>

<h3>System Calls</h3>

<p>
We can make system calls by call the functions exported by the
<code>syscall</code> standard package.
Please beware that, different from other standard packages,
the functions in the <code>syscall</code> standard package are operating system dependent.
</p>

<h3>The <code>go/*</code> Standard Packages</h3>

<p>
The <code>go/*</code> standard packages provide functionalities of
parsing Go source files, which are very useful to write custom Go tools.
Please read <a href="https://github.com/golang/example/tree/master/gotypes"><code>go/types</code>: The Go Type Checker</a>
and <a href="https://golang.org/pkg/go/">package documentation</a> for how to use these packages.
</p>

<h3>More Build Modes</h3>

<p>
The <code>go build</code> command in the official Go SDK supports several build modes.
Please run <code>go help buildmode</code> to show the available build modes
or read the explanations for <a href="https://golang.org/cmd/go/#hdr-Build_modes">-buildmode option</a> instead.
Except the <b>default</b> build mode, the most used build mode may be the <b>plugin</b> build mode.
We can use the functions in <a href="https://golang.org/pkg/plugin/">the <code>plugin</code> standard package</a>
to load and use the Go plugin files outputted by using the <b>plugin</b> build mode.
</p>




